package com.dji.compose_learning.todolist

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class TodoListViewModel : ViewModel() {
    private val _todolist = MutableLiveData(listOf(
        TodoItem("起床", TodoIcon.Done),
        TodoItem("刷牙", TodoIcon.Square),
        TodoItem("洗脸", TodoIcon.Default),
        TodoItem("吃早饭", TodoIcon.Event),
        TodoItem("坐校车", TodoIcon.Event),
        TodoItem("上早自习", TodoIcon.Event)
    ))

    val todolist:LiveData<List<TodoItem>> = _todolist

    //添加item
    fun addItem(item:TodoItem) {
        _todolist.postValue(_todolist.value?.toMutableList()!! + listOf(item))
    }

    //移除item
    fun removeItem(item:TodoItem) {
        _todolist.postValue(_todolist.value?.toMutableList()!! - item)
    }
}